﻿@Html.DevExpress().GridLookup(
    settings => {
        settings.Name = "gridLookup";
        settings.KeyFieldName="TagName";
        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ShowSelectCheckbox = true;
        settings.Columns.Add("TagName");
        settings.Columns.Add("Rank").Settings.AllowAutoFilter = DefaultBoolean.False;
        settings.Properties.SelectionMode = DevExpress.Web.ASPxGridLookup.GridLookupSelectionMode.Multiple;
        settings.Properties.TextFormatString = "{0}";
        settings.Properties.MultiTextSeparator = ", ";
        settings.Properties.Width = 250;
        
        settings.GridViewProperties.CallbackRouteValues = new { Controller = "GridLookup", Action = "MultiSelectPartial" };
        settings.GridViewProperties.Settings.ShowFilterRow = true;
        settings.GridViewProperties.Settings.ShowStatusBar = GridViewStatusBarMode.Visible;
        settings.GridViewProperties.SetStatusBarTemplateContent(c => {
            ViewContext.Writer.Write("<div style=\"padding: 2px 8px 2px 0; float: right\">");
            Html.DevExpress().Button(
                btnSettings => {
                    btnSettings.Name = "btnClose";
                    btnSettings.UseSubmitBehavior = false;
                    btnSettings.Text = "Close";
                    btnSettings.ClientSideEvents.Click = "CloseGridLookup";
                }
            )
            .Render();
            ViewContext.Writer.Write("</div>");    
        });
        
        settings.DataBound = (sender, e) => {
            var gridLookup = (MVCxGridLookup)sender;
            gridLookup.GridView.Width = 250;
        };
}).BindToXML("~/App_Data/GridLookupData.xml", "//Tags/*").GetHtml()